package com.zone.infrastructure.persistent.repository;

import com.google.common.collect.Lists;
import com.zone.domain.strategy.model.entity.RuleTreeNodeEntity;
import com.zone.domain.strategy.repository.IRuleTreeRepository;
import com.zone.infrastructure.persistent.dao.IRuleTreeNodeDao;
import com.zone.infrastructure.persistent.po.RuleTreeNode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: zongzi
 * @description: TODO
 * @date: 2025/2/27
 */
@Slf4j
@Repository
public class RuleTreeRepository implements IRuleTreeRepository {
    @Autowired
    private IRuleTreeNodeDao ruleTreeNodeDao;

    @Override
    public List<RuleTreeNodeEntity> queryTreeNodeListByTreeId(List<String> treeIds) {
        if (CollectionUtils.isEmpty(treeIds)) {
            return Lists.newArrayList();
        }
        List<RuleTreeNode> ruleTreeNodeList = ruleTreeNodeDao.queryTreeNodeListByTreeId(treeIds);
        if (CollectionUtils.isEmpty(ruleTreeNodeList)) {
            return Lists.newArrayList();
        }
        return ruleTreeNodeList.stream()
                .map(ruleTreeNode -> {
                    RuleTreeNodeEntity ruleTreeNodeEntity = new RuleTreeNodeEntity();
                    ruleTreeNodeEntity.setTreeId(ruleTreeNode.getTreeId());
                    ruleTreeNodeEntity.setRuleKey(ruleTreeNode.getRuleKey());
                    ruleTreeNodeEntity.setRuleDesc(ruleTreeNode.getRuleDesc());
                    ruleTreeNodeEntity.setRuleValue(ruleTreeNode.getRuleValue());
                    return ruleTreeNodeEntity;
                }).collect(Collectors.toList());
    }
}
